using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;

namespace AgileBoard.Web.Presentation
{
    // http://geekswithblogs.net/bdiaz/archive/2010/04/09/handy-asp.net-mvc-2-extension-methods-ndash-where-am-i.aspx

    public static class MenuExtensions
    {
        public static MvcHtmlString ActionMenuItem(this HtmlHelper htmlHelper, String linkText, String actionName, String controllerName)
        {
            string menuItem;
            var actionLink = htmlHelper.ActionLink(linkText, actionName, controllerName).ToString();
            
            menuItem = htmlHelper.ViewContext.RequestContext.IsCurrentRoute(controllerName)
                           ? new TagBuilder("strong"){ InnerHtml = actionLink}.ToString()
                           : actionLink;

            return MvcHtmlString.Create(menuItem);
        }

        public static bool IsCurrentRoute(this RequestContext context, String controllerName)
        {
            RouteData routeData = context.RouteData;
            bool current = false;

            if ((String.IsNullOrEmpty(controllerName)) || (routeData.GetRequiredString("controller") == controllerName))
            {
                current = true;
            }

            return current;
        }
    }
}